package sgd.tp2.client.net;

import sgd.tp2.api.net.NetProtocolType;
import sgd.tp2.client.cmdline.ConfigurationOptions;
import sgd.tp2.client.net.tcp.TCPClientBytes;
import sgd.tp2.client.net.tcp.TCPClientCSV;
import sgd.tp2.client.net.tcp.TCPClientJSON;
import sgd.tp2.client.net.tcp.TCPClientObject;
import sgd.tp2.client.net.tcp.TCPClientXML;
import sgd.tp2.client.net.udp.UDPClientBytes;
import sgd.tp2.client.net.udp.UDPClientCSV;
import sgd.tp2.client.net.udp.UDPClientJSON;
import sgd.tp2.client.net.udp.UDPClientObject;
import sgd.tp2.client.net.udp.UDPClientXML;

public final class ClientFactory {

	public static Client getClientInstance(ConfigurationOptions options) {
		if (options.protocol == NetProtocolType.TCP) {
			switch (options.format) {
				default:
					return new TCPClientXML(options.format, options.serverAddress,
							options.serverPort);
				case JSON:
					return new TCPClientJSON(options.format, options.serverAddress,
							options.serverPort);
				case CSV:
					return new TCPClientCSV(options.format, options.serverAddress,
							options.serverPort);
				case OBJECT:
					return new TCPClientObject(options.format, options.serverAddress,
							options.serverPort);
				case BYTES:
					return new TCPClientBytes(options.format, options.serverAddress,
							options.serverPort);
			}
		} else {
			switch (options.format) {
				default:
					return new UDPClientXML(options.format, options.serverAddress,
							options.serverPort, options.packetSize);
				case JSON:
					return new UDPClientJSON(options.format, options.serverAddress,
							options.serverPort, options.packetSize);
				case CSV:
					return new UDPClientCSV(options.format, options.serverAddress,
							options.serverPort, options.packetSize);
				case OBJECT:
					return new UDPClientObject(options.format, options.serverAddress,
							options.serverPort, options.packetSize);
				case BYTES:
					return new UDPClientBytes(options.format, options.serverAddress,
							options.serverPort, options.packetSize);
			}
		}
	}
}
